home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / GRAPHICS / VOXRAY.ZIP / VOXROW.ASM < prev    next >
Encoding:
Assembly Source File  |  1995-10-03  |  4.8 KB  |  176 lines

  1. ; ///////////////////////////////////////////////////////////////////////////
  2. ; Voxrow.asm - The inner loop of a program to draw voxel terrain
  3. ; Er um, this code is copyright @1994 Matt Howard, and stuff.
  4. ; But why copyright a program? It's just an instrument of the imperialist
  5. ; capatalist regime. In a true socialist society, we'd all share our code.
  6. ; And someone would tape Bill Gates mouth shut. Harmony would prevail.
  7. ; But anyway... here's the code...
  8. ; /////////////////////////////////////////////////////////////////////////
  9.  
  10. .CODE
  11. .386
  12.  
  13. X_LOC_BOUNDER equ 00ffffffh
  14. Y_LOC_BOUNDER equ 0ff000000h
  15. VOX_FP_SHIFT equ 10h
  16. LIGHT_FP_SHIFT equ 08h
  17. ALT_TO_COL_DIFF equ 0ffffh
  18. G_TABLE_SHIFT equ 9
  19. G_TABLE_ADJUST equ 100h
  20. LIGHT_AND equ 0f0h
  21. COLOR_AND equ 0fh
  22.  
  23. EXTRN "C", x_inc:DWORD; speed at which to go across map in x
  24. EXTRN "C", y_inc:DWORD; speed at which to go across map in y
  25. EXTRN "C", x_loc:DWORD; fixed-point x loc in map
  26. EXTRN "C", y_loc:DWORD; fixed-point y loc in map
  27. EXTRN "C", vox_buff:DWORD; buffer in which to draw
  28. EXTRN "C", starting_y:WORD; highest value to starting drawing at
  29. EXTRN "C", cur_scaler:DWORD ; array holds data to scale altitudes to screen
  30. EXTRN "C", alt_array:DWORD ; grid of altitudes
  31. EXTRN "C", prev_vox_colors:DWORD ; array to save last trace colors
  32. EXTRN "C", prev_vox_heights:DWORD ; array to save last trace heights
  33. EXTRN "C", g_table:DWORD ; scaler to get gauraud interpolation w/o division
  34. EXTRN "C", y_jumps:DWORD ; scaler to get y line offset w/o multiplication
  35. EXTRN "C", WINDOW_HEIGHT:WORD ; height of view window
  36. EXTRN "C", v_horiz_length:DWORD ; length horizontally of current vox run
  37. EXTRN "C", PHYS_SCREEN_WIDTH:DWORD ; length of physical screen
  38. EXTRN "C", v_light_table:DWORD ; table of values to change light
  39.  
  40. PUBLIC Draw_Vox_Row_
  41.  
  42. Draw_Vox_Row_ PROC NEAR C
  43.  
  44.    pushad
  45.  
  46.    mov esi, v_horiz_length
  47.    dec esi
  48.  
  49.    mov ebp, x_loc
  50. VOX_OUT_LOOP:
  51.  
  52.       xor ecx, ecx
  53.       xor ebx, ebx
  54.       xor edi, edi
  55.  
  56.       ; get x,y location of next pixel
  57.       mov eax, y_loc
  58.       and eax, Y_LOC_BOUNDER
  59.       and ebp, X_LOC_BOUNDER
  60.       add eax, ebp
  61.       shr eax, VOX_FP_SHIFT
  62.  
  63.       ; get altitude
  64.       mov edx, alt_array
  65.       add edx, eax
  66.       mov cl, [edx]
  67.  
  68.       ; get color
  69.       ; Note: altitude & color array are next to each other
  70.       ; in memory for speed
  71.       add edx, ALT_TO_COL_DIFF
  72.       mov bl, [edx]
  73.  
  74.       ; get lighted value
  75.       mov edx, v_light_table;
  76.       mov bl, [edx+ebx];
  77.  
  78.       ; scale altitude
  79.       mov edx, cur_scaler
  80.       ; note: ecx added twice since it is word
  81.       add edx,ecx
  82.       add edx,ecx
  83.       mov cx, [edx]
  84.  
  85.       ; add base value and clip against screen for final value
  86.       add cx, starting_y
  87.  
  88.       ; too high
  89.       jns not_too_high
  90.       mov cx, 0
  91.  
  92. not_too_high:
  93.  
  94.       ; get difference in color
  95.       ; Note: previous height and previous color are next to each other
  96.       ; in memory for speed
  97.       mov edx, prev_vox_colors;
  98.       add edx, esi
  99.       xor eax, eax        
  100.       mov al, [edx]
  101.       mov [edx], bl
  102.  
  103.       ; get previous y        
  104.       mov edx, prev_vox_heights;
  105.       ; note: esi added twice for since it is word                             
  106.       add edx, esi
  107.       add edx, esi
  108.       mov di, [edx]
  109.       sub di, cx
  110.       jbe NO_DRAW
  111.  
  112.          mov [edx], cx ; save current value for next round, this seems
  113.                      ; out of place, but helps speed
  114.       
  115.          ; get gauraud interpolation value
  116.          mov edx, edi
  117.          shl edx, G_TABLE_SHIFT
  118.          add edx, eax
  119.          add edx, G_TABLE_ADJUST
  120.          sub edx, ebx
  121.          ; adjust for long
  122.          add edx, edx
  123.          add edx, g_table
  124.          mov ax, [edx]
  125.  
  126.          ; get screen starting pos
  127.          mov edx, y_jumps
  128.          shl ecx, 2
  129.          add edx, ecx
  130.          mov ecx, [edx]
  131.          add ecx, esi
  132.          add ecx, vox_buff
  133.  
  134.          ; set up values for gauroud loop
  135.          mov bh, bl
  136.          xor bl,bl
  137.  
  138. VOX_IN_LOOP:
  139.  
  140.             ; note: to achieve super speed,
  141.             ; fixed point light is exactly 8 bits in the decimal
  142.             ; this way, the integer portion can be accessed
  143.             ; directly through byte register "bh"
  144.             ; cutting inner loop total to 5 instructions! (including counter update)
  145.  
  146.             ; get the color val and throw it on that screen
  147.             mov [ecx], bh
  148.  
  149.             ; update light val and screen pos
  150.             add ecx, PHYS_SCREEN_WIDTH
  151.             add bx, ax
  152.  
  153.             ; and loop
  154.             dec edi
  155.             jnz VOX_IN_LOOP
  156.  
  157. NO_DRAW:
  158.   
  159.       ; update positions in map
  160.       mov eax, y_inc
  161.       add y_loc, eax
  162.       mov eax, x_inc
  163.       add ebp, eax
  164.  
  165.       ; and loop
  166.       dec esi
  167.       jns VOX_OUT_LOOP
  168.  
  169.    popad
  170.    ret
  171.  
  172. Draw_Vox_Row_ ENDP
  173.  
  174. END
  175.  
  176.